home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Gamer Resource Kit / Hardcore Gamer Resource Kit - Disc 2.iso / Utils / UNIX / UNZIP520 / WINGUI / UPDATELB.C < prev    next >
C/C++ Source or Header  |  1996-02-06  |  6KB  |  167 lines

  1. /* updatelb.c module of WizUnzip.
  2.  * Author: Robert A. Heath
  3.  * I, Robert Heath, place this source code module in the public domain.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include "wingui\wizunzip.h"
  8.  
  9. #define UNZIP_INTERNAL
  10. #include "unzip.h"
  11.  
  12. /* Update Buttons is called when an event possibly modifies the
  13.  * number of selected items in the listbox.
  14.  * The function reads the number of selected items.
  15.  * A non-zero value enables relevant buttons and menu items.
  16.  * A zero value disables them.
  17.  */
  18. #ifdef __BORLANDC__
  19. #pragma argsused
  20. #endif
  21. void UpdateButtons(HWND hWnd)
  22. {
  23. BOOL fButtonState;
  24.  
  25. if (lpumb->szFileName[0] &&
  26.    SendMessage(hWndList, LB_GETSELCOUNT, 0, 0L)) /* anything selected ? */
  27.    {
  28.    fButtonState = TRUE;
  29.    }
  30. else
  31.    {
  32.    fButtonState = FALSE;
  33.    }
  34. WinAssert(hExtract);
  35. EnableWindow(hExtract, fButtonState);
  36. WinAssert(hDisplay);
  37. EnableWindow(hDisplay, fButtonState);
  38. WinAssert(hTest);
  39. EnableWindow(hTest, fButtonState);
  40. WinAssert(hShowComment);
  41. EnableWindow(hShowComment, (BOOL)(fButtonState && cchComment ? TRUE : FALSE));
  42.  
  43. WinAssert(hCopyArchive);
  44. EnableWindow(hCopyArchive, fButtonState);
  45. WinAssert(hMoveArchive);
  46. EnableWindow(hMoveArchive, fButtonState);
  47. WinAssert(hRenameArchive);
  48. EnableWindow(hRenameArchive, fButtonState);
  49. WinAssert(hDeleteArchive);
  50. EnableWindow(hDeleteArchive, fButtonState);
  51.  
  52. EnableMenuItem(hMenu, IDM_EXTRACT, (fButtonState ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  53. EnableMenuItem(hMenu, IDM_DISPLAY, (fButtonState ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  54. EnableMenuItem(hMenu, IDM_TEST, (fButtonState ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  55.  
  56. EnableMenuItem(hMenu, IDM_COPY_ARCHIVE, (fButtonState ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  57. EnableMenuItem(hMenu, IDM_MOVE_ARCHIVE, (fButtonState ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  58. EnableMenuItem(hMenu, IDM_RENAME_ARCHIVE, (fButtonState ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  59. EnableMenuItem(hMenu, IDM_DELETE_ARCHIVE, (fButtonState ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  60.  
  61. EnableMenuItem(hMenu, IDM_SHOW_COMMENT,
  62.    (BOOL)(fButtonState && cchComment ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  63.  
  64. if (lpumb->szFileName[0] != '\0')
  65.    {
  66.    EnableMenuItem(hMenu, IDM_COPY_ARCHIVE, MF_ENABLED|MF_BYCOMMAND);
  67.    EnableMenuItem(hMenu, IDM_MOVE_ARCHIVE, MF_ENABLED|MF_BYCOMMAND);
  68.    EnableMenuItem(hMenu, IDM_DELETE_ARCHIVE, MF_ENABLED|MF_BYCOMMAND);
  69.    EnableMenuItem(hMenu, IDM_RENAME_ARCHIVE, MF_ENABLED|MF_BYCOMMAND);
  70.    }
  71. else
  72.    {
  73.    EnableMenuItem(hMenu, IDM_COPY_ARCHIVE, (fButtonState ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  74.    EnableMenuItem(hMenu, IDM_MOVE_ARCHIVE, (fButtonState ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  75.    EnableMenuItem(hMenu, IDM_DELETE_ARCHIVE, (fButtonState ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  76.    EnableMenuItem(hMenu, IDM_RENAME_ARCHIVE, (fButtonState ? MF_ENABLED : MF_DISABLED|MF_GRAYED)|MF_BYCOMMAND);
  77.    }
  78. }
  79.  
  80. /* Update List Box attempts to fill the list box on the parent
  81.  * window with the next "cListBoxLines" of personal data from the
  82.  * current position in the file.
  83.  * UpdateListBox() assumes that the a record has been read in when called.
  84.  * The cZippedFiles variable indicates whether or not a record exists.
  85.  * The bForward parameter controls whether updating precedes forward
  86.  * or reverse.
  87.  */
  88. #ifdef __BORLANDC__
  89. #pragma argsused
  90. #endif
  91. void UpdateListBox(HWND hWnd)
  92. {
  93. SendMessage(hWndList, LB_RESETCONTENT, 0, 0L);
  94. InvalidateRect( hWndList, NULL, TRUE );
  95. UpdateWindow( hWndList );
  96. cZippedFiles = 0;
  97.  
  98. if (lpumb->szFileName[0])       /* file selected? */
  99.    {
  100.         /* if so -- stuff list box              */
  101.    SendMessage(hWndList, WM_SETREDRAW, FALSE, 0L);
  102.    /* Call here when a file has been initially selected */
  103.  
  104. lpDCL->ncflag = 0;
  105. lpDCL->ntflag = 0;
  106. lpDCL->nvflag = (int)(!uf.fFormatLong ? 1 : 2);
  107. lpDCL->nUflag = 1;
  108. lpDCL->nzflag = 0;
  109. lpDCL->ndflag = 0;
  110. lpDCL->noflag = 0;
  111. lpDCL->naflag = 0;
  112. lpDCL->argc   = 0;
  113. lpDCL->lpszZipFN = lpumb->szFileName;
  114. lpDCL->FNV = NULL;
  115. #ifdef USEWIZUNZDLL
  116. (*DllProcessZipFiles)(lpDCL);
  117. #else
  118.    if (FSetUpToProcessZipFile(lpDCL))
  119.       {
  120.       process_zipfiles(__G);
  121.       }
  122.    else
  123.       {
  124.       MessageBox(hWndMain, szNoMemory, NULL,
  125.                   MB_OK|MB_ICONEXCLAMATION);
  126.       }
  127.  
  128.    TakeDownFromProcessZipFile();
  129. #endif
  130. #ifndef NEED_EARLY_REDRAW
  131.    SendMessage(hWndList, WM_SETREDRAW, TRUE, 0L);
  132.    InvalidateRect(hWndList, NULL, TRUE);   /* force redraw         */
  133. #endif
  134.    cZippedFiles = (WORD)SendMessage(hWndList, LB_GETCOUNT, 0, 0L);
  135.    assert((int)cZippedFiles != LB_ERR);
  136.    if (cZippedFiles)   /* if anything went into listbox set to top */
  137.       {
  138. #ifdef NEED_EARLY_REDRAW
  139.       UpdateWindow(hWndList); /* paint now!                   */
  140. #endif
  141.       SendMessage(hWndList, LB_SETTOPINDEX, 0, 0L);
  142.       }
  143. #ifdef NEED_EARLY_REDRAW
  144.    else /* no files were unarchived!                           */
  145.       {
  146.             /* Add dummy message to initialize list box then clear it
  147.              * to prevent strange problem where later calls to
  148.              * UpdateListBox() do not result in displaying of all contents.
  149.              */
  150.       SendMessage(hWndList, LB_ADDSTRING, 0, (LONG)(LPSTR)" ");
  151.       UpdateWindow(hWndList); /* paint now!                   */
  152.       }
  153. #endif
  154.    }
  155. #ifdef NEED_EARLY_REDRAW
  156. else
  157.    {
  158.         /* Add dummy message to initialize list box then clear it
  159.          * to prevent strange problem where later calls to
  160.          * UpdateListBox() do not result in displaying of all contents.
  161.          */
  162.    SendMessage(hWndList, LB_ADDSTRING, 0, (LONG)(LPSTR)" ");
  163.    UpdateWindow(hWndList); /* paint now!                   */
  164.    }
  165. #endif
  166. }
  167.